/**
 * Created by limeng on 16/8/31.
 */
delegateApp.controller("ArticleCreationCtrl", function ($scope, $http, $rootScope) {
    $scope.article = {
        authorId : $rootScope.delegate.id,
        title : '',
        type : 0,
        content : ''
    };
    $scope.title = '新建文章';
    
    $scope.publishArticle = function () {
        if ($scope.article.title == '') {
            bootbox.alert("请输入标题!");
            return;
        }

        $scope.article.content = $('#textEditor')[0].innerHTML;
        $http.post('/article/', $scope.article)
            .success(function (data) {
                if (data.state == true) {
                    bootbox.alert('发布成功!', function () {
                        history.go(-1);
                    });
                } else {
                    bootbox.alert('发布失败,服务器拒绝，错误提示为：\n' + data.result);
                }
            }).error(function () {
            showAlert('发布失败', '服务器没有响应请求！')
        });
    };
});